package com.pingan.haofang.searchcloud.common.handler;

import org.springframework.core.PriorityOrdered;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.NoHandlerFoundException;
import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 异常处理
 *
 * @author zhangbi
 */
@Component
public class SearchHandlerExceptionResolver extends DefaultHandlerExceptionResolver implements PriorityOrdered {

    @Override
    public int getOrder() {
        return HIGHEST_PRECEDENCE;
    }

    @Override
    protected ModelAndView handleNoHandlerFoundException(NoHandlerFoundException ex, HttpServletRequest request,
                                                         HttpServletResponse response, Object handler) throws IOException {

        response.sendRedirect("/");
        return new ModelAndView();
    }
}
